<template>
  <div>
    <el-container>
      <el-header>
        <div
          style="position: absolute; left: 0px; top: 0px; z-index: 9999999"
          id="screenfull"
          @click="isScreenFull"
          class="screenfulls"
          allowfullscreen="true"
          :fullscreen.sync="isScreenFull"
        >
          <el-button style="display: ">点击全屏</el-button>
        </div>

        <el-button style="float: right; margin-top: 10px" @click="quit">
          退出登录
        </el-button>
      </el-header>

      <el-container>
        <el-aside :width="isCollapse ? '65px' : '200px'">
          <template>
            <div style="width: 100%; height: 100px">
              <img
                src="../assets/img/pic/logo/white.png"
                alt=""
                style="width: 100%; height: 100%"
                @click="isCollapse = !isCollapse"
              />
            </div>
          </template>
          <el-col :span="12">
            <el-menu
              :collapse="isCollapse"
              router
              default-active="2"
              class="el-menu-vertical-demo"
              background-color="#fe6d55"
              text-color="#fff"
              active-text-color="#ffd04b"
            >
              <el-submenu
                :index="item.id + ''"
                v-for="item in listmenus.menus"
                :key="item.id"
              >
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{ item.title }}</span>
                </template>

                <el-menu-item-group>
                  <el-menu-item
                    :index="ele.url"
                    v-for="ele in item.children"
                    :key="ele.id"
                    >{{ ele.title }}</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-aside>

        <el-main>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/index' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view> </router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//引入全屏插件
import screenfull from "screenfull";

export default {
  data() {
    return {
      listmenus: [],
      isCollapse: false,
    };
  },
  methods: {
    quit() {
      localStorage.removeItem("token");
      this.$message("退出成功");
      this.$router.push("/login");
    },
    isScreenFull() {
      if (!screenfull.isEnabled) {
        // 如果不支持进入全屏，发出不支持提示
        this.$message({
          message: "您的浏览器版本过低不支持全屏显示！",
          type: "warning",
        });
        return false;
      }
      screenfull.toggle();
    },
  },
  created() {
    this.listmenus = JSON.parse(localStorage.getItem("token"));
    // console.log(this.listmenus);
    this.$nextTick(() => {
      this.isScreenFull(); //以下两种方式二选一，均可
      // setTimeout(() => {
      //   document.querySelector("#screenfull").click()
      // })
    });
  },
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang="scss" scoped>

// 导航栏样式
.el-menu-vertical-demo {
  width: 200px;
  height: 100%;
  background-color: #545c64;
  color: #fff;
  border-right: 1px solid #d3dce6;
}
.screenfulls {
  margin-left: 85%;
  margin-top: 7px;
}

.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  // text-align: center;
  line-height: 200px;
  height: 100vh;
  width: 50px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
::v-deep.el-submenu {
  width: 200px;
}
</style>
